<?php
/**
 * Auto Complete Customer Seach Interface
 * IT will return customer id and name
 *
 * @author Xavier VILAIN
 *
 */

use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Connection;
use Fox\Common\Customer;
$terms = "%".Xview::instance()->val("term")."%";
$id = Xview::instance()->val("customerid");
if(!empty($id))
{
	$data = array();
	$customer = \Fox\Dao::load(Customer::className(),$id);
	/* @var $customer Customer */
	$fragments[] = new Fox\Dao\SqlFragment(" loekz = ? AND LOWER(name1) LIKE LOWER(?) "
	,array(0,$terms),
	array(Type::INTEGER,type::STRING));
	$partners = $customer->customerPartners($fragments);
	foreach($partners as $partner)
	{
		$label = $partner->name1;
		$data[] = array('id' => $partner->customerid,'label' => $label );
	}
	echo json_encode($data);
}
